package aRole

import (
	"context"
	"github.com/jinzhu/copier"
	"t-go-zero/service/user/api/internal/svc"
	"t-go-zero/service/user/api/internal/types"
	"t-go-zero/service/user/rpc/userclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type ARoleListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewARoleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ARoleListLogic {
	return &ARoleListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ARoleListLogic) ARoleList(req *types.ARoleListRequest) (resp *types.Response, err error) {

	all, err := l.svcCtx.UserRpc.ARoleList(l.ctx, &userclient.ARoleListReq{
		Current:  req.Current,  // 页码
		PageSize: req.PageSize, // 页数
		Name:     req.Name,     // 角色名称
		Remark:   req.Remark,   // 备注
	})

	// 硬拷贝对象过程
	var result ARoleListResp
	_ = copier.Copy(&result, all)

	return &types.Response{
		Code: 0,
		Msg:  "成功",
		Data: result,
	}, nil
}

type ARoleListResp struct {
	Total int64            `json:"total"`
	List  []*ARoleDataList `json:"list"`
}

type ARoleDataList struct {
	Id          int64  `json:"id"`           // 角色ID,
	Name        string `json:"name"`         // 角色名称,
	Remark      string `json:"remark"`       // 备注,
	CreatedName string `json:"created_name"` // 创建人,
	CreatedAt   int64  `json:"created_at"`   // 创建时间
}
